<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "issue".
 *
 * @property int $id
 * @property int $projectId
 * @property int $contactId
 * @property string|null $name
 * @property string|null $detail
 * @property int|null $priority start counts, max to 3
 * @property int|null $state 0 for new, 1 for working on it, 2 for suspended, 3 for finished, 10 for deleted
 * @property string|null $date request date
 * @property string|null $createdAt
 * @property string|null $updatedAt
 */
class Issue extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'issue';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['projectId','contactId'], 'required'],
            [['contactId', 'priority', 'state'], 'integer'],
            [['detail'], 'string'],
            [['date', 'createdAt', 'updatedAt'], 'safe'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'projectId' => 'Project ID',
            'contactId' => 'Contact ID',
            'name' => Yii::t('app', 'Issue'),
            'detail' => Yii::t('app', 'Detail'),
            'priority' => Yii::t('app', 'Priority'),
            'state' => Yii::t('app', 'State'),
            'date' => Yii::t('app', 'Date'),
            'createdAt' => Yii::t('app', 'Created At'),
            'updatedAt' => Yii::t('app', 'Updated At'),
        ];
    }

    public function getProject(){
        return $this->hasOne(Project::class, ['id' => 'projectId']);
    }

    public function getContact(){
        return $this->hasOne(Contact::class, ['id' => 'contactId']);
    }
}
